<html>  
  <head>  
        <meta charset="utf-8">  
        <title>5.5.1 散点图的制作</title>  
  </head> 
  <style>
  
.axis path,
.axis line{
	fill: none;
	stroke: black;
	shape-rendering: crispEdges;
}
 
.axis text {
	font-family: sans-serif;
	font-size: 11px;
}

  </style>
<body>

<script src="../../d3/d3.min.js" charset="utf-8"></script> 
<script>  

//圆心数据
var center = [[0.5,0.5],[0.7,0.8],[0.4,0.9],[0.11,0.32],[0.88,0.25],
			   [0.75,0.12],[0.5,0.1],[0.2,0.3],[0.4,0.1],[0.6,0.7]];

var width  = 500;	//SVG绘制区域的宽度
var height = 500;	//SVG绘制区域的高度
	
var svg = d3.select("body")			//选择<body>
			.append("svg")			//在<body>中添加<svg>
			.attr("width", width)	//设定<svg>的宽度属性
			.attr("height", height);//设定<svg>的高度属性
			
//x轴宽度
var xAxisWidth = 300;

//y轴宽度
var yAxisWidth = 300;
			
//x轴比例尺
var xScale = d3.scale.linear()
				.domain([0, 1.2 * d3.max(center,function(d){ return d[0]; })])
				.range([0,xAxisWidth]);

//y轴比例尺
var yScale = d3.scale.linear()
				.domain([0, 1.2 * d3.max(center,function(d){ return d[1]; })])
				.range([0,yAxisWidth]);			
	
//外边框
var padding = { top: 30 , right: 30, bottom: 30, left: 30 };

//绘制圆
var cirlce = svg.selectAll("circle")
				.data(center)		//绑定数据
				.enter()			//获取enter部分
				.append("circle")	//添加circle元素，使其与绑定数组的长度一致
				.attr("fill","black")		//设置颜色为black
				.attr("cx", function(d){		//设置圆心的x坐标
					return padding.left + xScale(d[0]);
				})
				.attr("cy", function(d){		//设置圆心的y坐标
					return height- padding.bottom - yScale(d[1]);
				})
				.attr("r", 5 );
				

var xAxis = d3.svg.axis()
				.scale(xScale)
				.orient("bottom")
				.ticks(5);

yScale.range([yAxisWidth,0]);
				
var yAxis = d3.svg.axis()
				.scale(yScale)
				.orient("left")
				.ticks(5);
				
svg.append("g")
		.attr("class","axis")
		.attr("transform","translate(" + padding.left + "," + (height - padding.bottom) +  ")")
		.call(xAxis);
			
svg.append("g")
		.attr("class","axis")
		.attr("transform","translate(" + padding.left + "," + (height - padding.bottom - yAxisWidth) +  ")")
		.call(yAxis); 
	
</script> 

</body>

</html>